CodeIgniter Forums

Full Version: Variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi everybody, I'm new to CodeIgniter and I am having an issue that i can't solve.. I got a cms to optimise and there is file views/templates/file.php and it some $variable. I''m struggling few days now to find where is that variable defined, which controler is in charge for that variable, and so on.
My question is where could iti be stored, there is not require or include, there is not passed data via $this->load->view($view, $data) anywhere..
if the view file is named "some_view.php", then use your IDE's search function to search for 'some_view' (without the .php). You'll most likely find a controller (could be a library or elsewhere as well) that is doing something like:

But don't search for that entire specific line...just the name of the view file. You don't know if there is a custom function used to load the view, so the syntax can't be guaranteed. But if you just search for the filename itself without .php, your IDE should find it easily.
I already tried that, but I can't find it. Thanks for trying to help anyway =D
It could be a variable that's being created dynamically. SeeĀ variable variables in PHP.
PHP Code:
$a 'world';
var_dump ($a$hello);

The result is:
string 'hello' (length=5)
string 'world' (length=5) 
The variable $hello was created but you never see it being created. This is why many PHP programmers say it's not a good practice. It can make debugging difficult.

But I don't know that this is what's going on in the code you're working on. I would first search the entire project for that variable. Some editors allow you to search all files in a project, or all files in a folder. If nothing else, you can download and install Agent Ransack, an excellent free file search application. An editor with a debugger would help too.
In general, start with the URL of the page, break it down into its parts, then check the routes. For example, if the page is or, you check the /application/config/routes.php file for 'controller/action' (or something similar, see the CI documentation for routing rules if you see something you don't understand).

If there is a rule in place, look up the appropriate controller according to the route. If there is not one in place, look up the controller in the first part of the URL ('controller' in the above example), usually under /application/controllers/.

Inside that controller will usually be a method (function) named for the action defined via the route or the URL. If you can't find this method, or the controller uses a special method, like _remap(), and you don't understand what's going on, check the CI documentation for controllers (and remapping function calls).

Usually the variable will be defined within that method or in some code called directly by that method, but a more complicated application may include a template library (which appears to be the case from the directory name for the view) or some other method of defining more complicated views. In these cases, variables may also be defined in the template library, a base controller, or even another view. If no documentation is available for the application, it's usually best to trace through the application until you gain a more thorough understanding of its behavior.