Welcome Guest, Not a member yet? Register   Sign In
add codigniter4 composer package
#1

(This post was last modified: 12-13-2022, 12:15 PM by sjender.)

Hi,
I am trying to get my codeigniter4 dependant package to work.
But I'm looking for some startup help getting my test controller to work.
Simple example:
return view('home');
This ends in: 
Code:
Invalid file: home.php
Which kind of makes sense I guess, but how do I point my controller in my package to the right Views location.
Structure of the package:

--- cms
-------Controllers
-----------TestController.php (this is where the view is returned)
-------Views
-----------home.php (I want to load this view)
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...html#views
Reply
#3

Sweet and simple as always!

Can you point me in the right direction on how to create Routes as well within my package?
Reply
#4

See https://github.com/kenjis/ci4-modules-te...Routes.php
Reply
#5

Yep, works as well....

Last question and then I can start building.....
How can I use assets (images, js, css) files in the package?
Can I make a folder public for example?
Reply
#6

(This post was last modified: 12-14-2022, 01:26 AM by JustJohnQ.)

You can make one or more folders in the public folder.
Then add them required files in your view like this:

Code:
<!-- jQuery -->

<script src="<?php echo base_url("Resources/plugins/jquery/jquery.js");?>"></script>
Reply
#7

You need to publish the assets.
See https://codeigniter4.github.io/CodeIgnit...es-example
Reply
#8

@kenjis solution is a better one...
Reply
#9

This does not seem to work as planned.
I have:
<?php
PHP Code:
namespace App\Publishers;

use 
CodeIgniter\Publisher\Publisher;

class 
Assets extends Publisher
{

    protected $source '../vendor/vendorname/vendorpackage/src/assets/';
    protected $destination FCPATH 'assets/cms';

    public function publish(): bool
    
{
        return $this
            
// Add all the files relative to $source
            ->addPath('dist')

            // Merge-and-replace to retain the original directory structure
            ->merge(true);
    }



This results in:
I'm not sure why it looks for ../assets...
Code:
PS C:\> php spark publish

CodeIgniter v4.2.10 Command Line Tool - Server Time: 2022-12-14 08:41:11 UTC-06:00


[CodeIgniter\Files\Exceptions\FileException]

__construct expects a valid directory.

at SYSTEMPATH\Files\FileCollection.php:50

Backtrace:
  1    SYSTEMPATH\Files\FileCollection.php:50
      CodeIgniter\Files\Exceptions\FileException::forExpectedDirectory('__construct')

  2    SYSTEMPATH\Publisher\Publisher.php:157
      CodeIgniter\Files\FileCollection::resolveDirectory('../assets/')

  3    SYSTEMPATH\Publisher\Publisher.php:117
      CodeIgniter\Publisher\Publisher()->__construct()

  4    SYSTEMPATH\Commands\Utilities\Publish.php:77
      CodeIgniter\Publisher\Publisher::discover('Publishers')

  5    SYSTEMPATH\CLI\Commands.php:63
      CodeIgniter\Commands\Utilities\Publish()->run([])

  6    SYSTEMPATH\CLI\CommandRunner.php:65
      CodeIgniter\CLI\Commands()->run('publish', [])

  7    SYSTEMPATH\CLI\CommandRunner.php:51
      CodeIgniter\CLI\CommandRunner()->index([])

  8    SYSTEMPATH\CodeIgniter.php:920
      CodeIgniter\CLI\CommandRunner()->_remap('index', [...])

  9    SYSTEMPATH\CodeIgniter.php:482
      CodeIgniter\CodeIgniter()->runController(Object(CodeIgniter\CLI\CommandRunner))

10    SYSTEMPATH\CodeIgniter.php:347
      CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

11    SYSTEMPATH\CLI\Console.php:48
      CodeIgniter\CodeIgniter()->run()

12    ROOTPATH\spark:98
      CodeIgniter\CLI\Console()->run()
Reply
#10

Do not use the relative path like '../vendor/vendorname/vendorpackage/src/assets/',
It is a bad practice, because you may not know the current directory, or
the current directory may be changed at runtime.

ROOTPATH . 'vendor/vendorname/vendorpackage/src/assets/'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB