Welcome Guest, Not a member yet? Register   Sign In
View cell controllers in a folder
#1

Hi, I started using view cells, which is really nice. I have the logic in App\Controllers and it works like a charm. Now I want to move them to App\Controllers\ViewCells folder, but I get an error.

"Unable to locate view cell class: \App\Controllers\ViewCells\DialogSound."

Any idea on how to solve this? Controllers seems to be the place for them since they inherit the basecontroller as well. They need some data.
Reply
#2

(This post was last modified: 08-19-2020, 01:00 PM by jreklund.)

Hi, you need to show us some code, on how you try to load it. And information on how you named them. As case sensitivity are importent.
Reply
#3

Did you change the namespace when you moved them?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(08-19-2020, 01:00 PM)jreklund Wrote: Hi, you need to show us some code, on how you try to load it. And information on how you named them. As case sensitivity are importent.

From the view:

PHP Code:
<?= view_cell('\App\Controllers\ViewCells\DialogSound::index'?>

app/Controllers/ViewCells/DialogSound.php (controller):

PHP Code:
namespace App\Controllers;

class 
DialogSound extends BaseController
{
    public function index()
    {
        $data['user'] = $this->datalib::$user;

        return view('viewCells/dialog_sound'$data);
    }


I tried changing the namespace to App\Controllers\ViewCells but then it wasn't the same as the BaseController.
Reply
#5

(08-20-2020, 03:08 AM)InsiteFX Wrote: Did you change the namespace when you moved them?

I tried... with App\Controllers\ViewCells - the same as the folder structure. But it extends BaseController which uses App\Controllers. My PHP knowledge is not good enough to figure this one out Smile
Reply
#6

(This post was last modified: 08-20-2020, 08:40 AM by jreklund.)

Hi, this should do the trick.

PHP Code:
namespace App\Controllers\ViewCells;

use \
App\Controllers\BaseController;
// rest as is 

or

PHP Code:
namespace App\Controllers\ViewCells;

class 
DialogSound extends \App\Controllers\BaseController
// rest as is 
Reply
#7

(08-20-2020, 08:39 AM)jreklund Wrote: Hi, this should do the trick.

PHP Code:
namespace App\Controllers\ViewCells;

use \
App\Controllers\BaseController;
// rest as is 

or

PHP Code:
namespace App\Controllers\ViewCells;

class 
DialogSound extends \App\Controllers\BaseController
// rest as is 

OMG it did! You are a legend! Thank you very much Smile Proof of my lacking PHP skills.

While you are here.... do you know if it's bad for performance to have 3-6 of these view cells on a single page? I have a template and I rather not have all data put into it. It becomes a mess quickly.
Reply
#8

Your welcome, namespacing itself are quite old, but I just learned it two years ago. And now I can't go back...

No, that's a rather small number, as I would do that for all my widgets. But remember to utilize some sort of cache, either in the view cell themselves or cache the entire page.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB