I'm putting an DOMpdf creator in my Codeigniter application, but now i need to get an require_once to the parent folder. Somehow Codeigniter doesn't allow me to do this the "normal" way.
This is my require_once
require_once("../dompdf_config.inc.php");
How can I make this work in Codeigniter?
Try something like:
//APPPATH gives you path till application/ folder
require_once(APPPATH.'your_DOMpdf_file_path');
Hope it helps
To load a config file in CodeIgniter, you can call the $this->config->load() method.
To load one of your custom config files you will use the following
function within the controller that needs it:
$this->config->load('filename');
Where filename is the name of your config file, without the .php file
extension.
If you need to load multiple config files normally they will be merged
into one master config array. Name collisions can occur, however, if
you have identically named array indexes in different config files. To
avoid collisions you can set the second parameter to TRUE and each
config file will be stored in an array index corresponding to the name
of the config file. Example:
// Stored in an array with this prototype: $this->config['blog_settings'] = $config
$this->config->load('blog_settings', TRUE);
Please see the section entitled Fetching Config Items below to learn
how to retrieve config items set this way.
The third parameter allows you to suppress errors in the event that a
config file does not exist:
$this->config->load('blog_settings', FALSE, TRUE);
http://codeigniter.com/user_guide/libraries/config.html
Related
Laravel 5.7.
If I navigate to a page that does not exist, I get 404 error page handling.
That view is located in vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/404.blade.php
However this file extends:
#extends('errors::illustrated-layout')
This is located in the same folder, and is named illustrated-layout.blade.php
So I guess that the errors:: part points to the specific folder., e.g. vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/
Question: Is this type of pointer something that could be created manually, so a person wouldn't have to write the entire path to a specific folder, when extending a view? Would make things much more clean.
You can add a view namespace and achieve the same result.
For example, you can add the following in AppServiceProvider#boot:
$this->app['view']->addNamespace('admin', base_path() . '/resources/views/admin');
and let's suppose you have a blade file in resources/views/admin/layouts/master.blade.php
you can access it with admin::layouts.master
I am a Drupal dev and new to code-igniter or any such php frameworks.
Now i have to modify an existing application done on codeigniter and the structure must be as follows:
example.com/motors
example.com/motors/car-for-sale
example.com/motors/car-for-rent etc.
Before it has only one url example.com/motors and i want to create more urls as mentioned above.
In the application\views\content folder i have the following structure:
application\views\content\motors.php
application\views\content\motors
application\views\content\motors\car-for-sale.php
In the application\controller folder i have the following structure:
application\controller\motors.php
application\controller\motors\motors.php
application\controller\motors\car-for-sale.php
I want to get the url example.com/motors & example.com/motors/car-for-sale from the files resides in the motors folder.Also how can i set a default file to load when i open example.com/motors?
You can't have a (controllers) directory that matches the name of a controller class at the same level. That is, since you have a controllers/motors.php, the files under controllers/motors/* will never be reached.
Instead (and this is the answer to your second question), you should set the default_controller name and rename controllers/motors.php to controllers/motors/<default_controller>.php.
Note that the default_controller setting points to a controller name (not a file location) and is applied to all directories. That is, if you set it to 'Default', then controllers/Default.php will be used when you open http://domain.tld/ and controllers/motors/Default.php will be used if you open http://domain.tld/motors/.
Also, your controller names MUST start with a capital letter, so default.php would be incorrect and should be Default.php instead. This might be working for you on Windows right now (because of its case-insensitive file system), but as soon as you upload your site to a Linux (or other UNIX-based) host, any classes with file names that don't start with a capital letter won't work.
It looks like you're trying to build a CodeIgniter site with a completely different paradigm from what it is designed around.
The structure you are after can be set up using the routes.php file within application/config
In there, you can set routes to go to any location needed, so for you, something like:
$routes['motors/cars-for-sale'] => 'motors/cars_for_sale';
$routes['motors/cars-for-rent'] => 'motors/cars_for_rent';
Then in application/controller you'd have a Motors.php file, which starts:
class Motors extends CI_Controller{
And also has the functions cars_for_sale and cars_for_rent
The mappings in routes sets this to link together.
In order to get the views you want for any given route, in the controller function, you'd have:
$this->load->view('path/to/view/file', $array_of_data); // view path does not need the .php extension
I'd recommend having a look and possibly even a follow through of the CodeIgniter tutorial in their documentation
As usual, to access CodeIgniter's configuration item from a $config array, I would use this function $this->config->item('some_item');. That's fine, but how can I access a config items from this file app/config/migration.php ? where $config['migration_enabled'] is located
I'm doing a $this->config->item('migration_enabled') or $this->config->item('migration_version'), but it returns me always FALSE, anyone know why ? And how can I work it out to make it accessible within the controller ?
You need to load the migration config before you access it. You can either load it on demand in your controller via:
$this->config->load('migration');
or you can autoload it in your config/autoload.php file by adding it to the $autoload['config'] array:
$autoload['config'] = array('migration');
I've been trying to load a configuration item into another configuration file for my CodeIgniter app.
The reason for doing this is that I don't want to go through all of the files to change same parameters when I, for example, change the server or want to change the site title.
I've tried to get the items I need from the main config.php file by using $this->config['site_title'], by loading the config file using $this->config->load('config') and by loading individual config item using $this->config->item('site_title') but all of these methods return errors that the configuration items could not be loaded.
Am I missing something?
you should load the config files from the CI instance within a Controller
$ci = & get_instance();
$item_name = $ci->config->item('item_name');
simply create your config file in your ci config folder
myconfig.php
in it
$config['my_site_title'] = 'TechNew.In - www.technew.in';
and load your config in the controller
$this->load->config('myconfig');
then get your value
$my_site_title = $this->config->item('my_site_title');
I've looked through all of the CI documentation, and done some Googling of it, but I still can't quite seem to figure out how to create a configuration file for a custom library in codeigniter. If somebody could even just point me in the direction of where in the docs I could find my answer it would be greatly appreciated.
I am creating a library in CI that makes use of several database columns that can vary in name between applications, so I would like the names to be stored in a custom config file. Then I would like to be able to load these values in the construct of the library.
So my two questions are:
1.) How do I name the config file, and how do I name variables within that file so they don't overwrite any other config vars?
2.) How do I get the values from within my library?
When i have questions like this i like to look at other projects that already do this. We utilized Tank_auth in almost all of our ci projects. This is a popular authentication library, which has its own custome config files
It just creates its own config file in application/config directory.
You could prefix your config items with your app name to ensure that they are unique
it then just loads it in the constructor:
$this->ci->load->config('tank_auth', TRUE);
If there is a config/libraryname.php file, it will be automatically loaded, just before library instanciation.
(so, beware of name conflicts with CI's config files)
Side note: this autoloading is disabled if you pass an array as the 2nd argument:
$this->load->library('thelibrary', array('param1' => 'value1'));
in your config /config/your_conf.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = Array(
'your_conf1' => 'your_conf_val1',
'your_conf2' => 'your_conf_val2',
'your_conf3' => 'your_conf_val3'
);
in your controller:
$this->config->load('your_conf');
var_dump((array)$this->config); //show all the configs including those in the your_conf.php