Error: ControllerController could not be found - php

i just created a controller like this:
<?php
class UsuarioController extends AppController {
}
?>
I went to http://urubu.zz.mu/controller/UsuarioController.php to test, and this was the result:
Error: ControllerController could not be found.
Error: Create the class ControllerController below in file: app/Controller/ControllerController.php
}
Theres no class ControllerController in my project.
I found a line in AppController(From CakePHP) :
App::uses('Controller', 'Controller');
But i dont know what it means and how to solve it.
Can anyone help? thanks

TLDR:
Read the wealth of documentation in the Online CakePHP Book to better understand CakePHP.
Accessing a Controller's index() action
In CakePHP, you access the index action of your Controller via the URL like this:
http://www.mydomain.com/usarios
You do NOT need to add "controller" to the URL.
The above would run the index() action within the UsariosController.
Accessing another action within a Controller
http://www.mydomain.com/usarios/register
This would run the register() action within the UsariosController.
Passing variables to actions within a Controller
http://www.mydomain.com/usarios/view/1
This would pass 1 to the register($userId) { action in your UsariosController.

Related

how to use another controller function without extends in our controller

how to use another controller function without extends in our controller
$this->load->library('../controllers/controllername');
already used
it is giving error =
Unable to locate the specified class: Session.php
Well you are not supposed to do that. If your controller uses repeatable logic, you should make class (Service for example), put the re-usable logic into it and call it in your controllers.
You can't use another controller function inside the controller. You can archive this in these two ways.
Create a Helper class
Create a generic model.

Session.php class is not able to load properly

I am working on PHP in Code-igniter. I want to call function of one controller on another controller. I have tried following code for that-
$this->load->library('../controllers/Benchmarking');
$this->Benchmarking->init_benchmark();
But after doing this I got an error as unable to locate the specified class:session.php
(Here, benchmarking is my controller and init_benchmark is that function which I want to call)
Can anyone help me, please?
You cannot call a function of a controller from another controller. CI won't allow it.
If you need the user to "move" from a controller to another, your best bet is to set session flashdata with all the data you need to pass from one controller to the other and then use a simple redirect.
$this->session->set_flashdata('handoff_data');
redirect('second_controller/function');
There are other ways, some more powerful, some more complicated, but this is by far the simplest one
please check your class name and extends properly. and create a common controller in your core folder like
class MY_Controller extends CI_Controller {
}
and call this controller in another controller's extends.

Layouts Throwing "Attempt to assign property of non-object" In Laravel 4

In the Layouts folder, I have a layout called signup.blade.php
In my controller, I'm assigning a layout to it like so:
protected $layout = 'layouts.signup';
In a separate folder, named "signup" I have a file called "signup1.blade.php" It contains your typical blade template stuff. It's a section called "content". Before the code I have
#section('content')
and it's got #stop at the end.
My controller looks like this:
public function SignUp()
{
$this->layout->content = View::make('signup.signup1');
}
The frustrating part is that this is working with another layout and controller. I've double checked they're the same, and this one does not work. Any suggestions would be greatly appreciated. Thank you.
So, assuming this controller extends BaseController (it must for $layout to work), the code execution sets $this->layout to View::make($this->layout).
Your error seems to show that $this->layout is not getting set to a View object correctly.
Try to run this and see if $this->layout is an object/class, and if so, what class it is.
public function SignUp()
{
echo gettype($this->layout);
echo get_class($this->layout);
}
Knowing what $this->layout does not get changed into a View object means that the setupLayout() method is either not called or, more likely, not the result of View::make($this->layout) is not a proper view (perhaps it's silently failing for some reason).
The above steps hopefully give you a clue into whats happening there. Perhaps layouts.signup isn't a layout the app is finding?
What do your routes look like?
Change
class UsersController extends Controller
to
class UsersController extends BaseController
Hopefully the author of Confide fixes this :-)

Html Helper CakePHP

Fatal error:
Call to a member function charset() on a non-object in D:\xampp\htdocs\demo\app\controllers\test_controller.php on line 10
PHP Controller Code:
<?php
class TestsController extends AppController
{
var $name="Tests";
var $helpers = array('Html');
var $uses=array();
# demo action to check wheather html helper is working or not
function index()
{ echo "111111111";
echo $this->Html->charset();
echo "22222222222";
}
}
?>
I am getting the above error while hitting the url: http://localhost/demo/tests
I am using CakePHP 2.0 ALPHA (latest version).
Please let me know what is the root cause.
Following CakePHP's MVC convention, you should by using behaviors in models, components in controllers and helpers in views. You are currently trying to use a helper in a controller, which won't work. I suggest you go back and have another look at the documentation, but for something like HtmlHelper::charset() you really want to be calling that once in the <head> tag of your layout (which is also part of the view layer):
http://book.cakephp.org/2.0/en/views.html?highlight=layout#layouts

CakePHP - Problems with ErrorHandler not extending AppController

I had been wondering why my error page caused certain pages of my site
not to render, but then I realized that it's because AppError extends
ErrorHandler instead of AppController. This caused some variables
that I set in AppController's beforeFilter method not to be sent to
the view. Since I can't access session variables from AppError, I
thought that I might be able to get away with using the classRegistry
to instantiate something that could and simply copying and pasting the
rest of my code from AppController's beforeFilter... but that isn't working, nor does it seem like a very elegant fix. Does anyone have any clues as to what
would be the best way to approach this? Thanks, David.
Your AppError class has a controller instance. You can call the beforeFilter manually:
<?php
class AppError extends ErrorHandler {
function error404() {
$this->controller->beforeFilter();
parent::error404();
}
}
?>
In CakePHP 2, you can do something like this to achieve the same effect. In app/Config/bootstrap.php, add this line:
Configure::write('Exception.renderer', 'AppExceptionRenderer');
Then create a file app/Lib/Error/AppExceptionRenderer.php with this code:
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
protected function _outputMessage($template) {
$this->controller->beforeFilter();
$this->controller->render($template);
$this->controller->afterFilter();
$this->controller->response->send();
}
}
Described more generally here: http://book.cakephp.org/2.0/en/development/exceptions.html#using-a-custom-renderer-with-exception-renderer-to-handle-application-exceptions
Edit: Updated link to point to correct location of the CakePHP 2.0 Book as of July 05, 2012.

Categories