Here is the folder structure in modules library
users->controllers->Users.php
users->config->autoload.php
welcome->controllers->Welcome.php
autoload.php
$autoload = array(
'helper' => array('url', 'form'),
'libraries' => array('session')
);
Welcome.php (located in modules/welcome/Welcome.php)
class Welcome extends MX_Controller {
public function index()
{
//load module
$this->load->module(array('users'));
}
}
I will get the following error :
Unable to locate the specified class: Session.php
Note:
url and form libraries are loaded correctly
In config/autoload.php file put below line
$autoload['libraries'] = array('database','form_validation','session');
Its work fine for me.
please load session in index function
$this->load->library('session');
Add this part in your function
Related
Im new to the codeigniter and cant understand why view is not loaded from the subfolders
i write simple controller and view file
Controller location application\controllers\Test.php
<?php
class Test extends CI_Controller{
public function index()
{
$data = array(
'name' => 'ivan'
);
$this->load->view('test/new', $this->data);
}
}
View location application\views\test\new.php
<div class="container">
<h1>Test</h1>
</div>
When i try to access url http://localhost/test/new im getting error
404 Page Not Found
The page you requested was not found.
Because you are in index function so just create another function named new if you want to run localhost/test/new
please run this url "http://localhost/test/", because your controller file index method are using.
I'm using codeIgniter to developing a website.
This website has a view sidebar and i call on view header with
<?php $this->load->view('sidebar');,
then in another view i call header by using <?php $this->load->view('header');
On sidebar i'm loading the session variables by
$papel = $this->session->userdata('papel');
$logado = $this->session->userdata('logado');
On sidebar it fits perfectly but in other pages like it's doesn't working anymore.
I'm already tried recalling the session variables and got the same results.
ps.: It's alerady autoloaded
Load session library in autoload:
Open autoload.php file located in application/config/autoload.php
Update $autoload['libraries'] variable
$autoload['libraries'] = array('database', 'email', 'session');
Load session in autoload.php found in config folder.
$autoload['libraries'] = array('database', 'session');
Plus to make a session you have to set it:
$this->session->set_userdata('session_name', 'value of the session');
Then calling it:
$this->session->userdata('session_name');
I have put together a CRUD application with CI 3. I am trying to load a mobile specific template (view) for the homepage. For this purpose I have:
1) Loaded the user_agent library:
$autoload['libraries'] = array('database', 'form_validation', 'user_agent');
2) Created a directory called mobile in the views directory and a home.php view file inside it.
3) The Home controller looks like this:
class Home extends CI_Controller {
public function index() {
$this->load->model('Customer');
$customers = $this->Customer->getCustomers();
if ($this->agent->is_browser()) {
$this->load->view('home', ['records'=>$customers]);
} else {
$this->load->view('mobile/home', ['records'=>$customers]);
}
}
}
The error I get is:
Failed opening required 'includes/header.php'
NOTE: At the top of my view files I have:
<?php require "includes/header.php"; ?>
The includes directory is directly in the views directory so I believe the first thing to do is use the application's root in the path above.
How do I do that?
try $this->load->view("includes/header"); instead of require includes/header.php;
I want to change views folder of yii2 to structure bellow
views
----default
----site
----index.php
----error.php
----login.php
In the siteController i'm using code bellow
public function actionIndex(){
return $this->render('default/index');
}
and error
The view file does not exist: D:\wamp\www\yii2\backend\views\site\default/index.php
Please help me
With your current code, the Site Controller search the view file under his view's folder /views/site, you need to get the right path:
$this->render('../default/site/index');
I suggest to create an alias for be more flexible, like #default_views in your main-local file:
'aliases' => [
'#default_views' => '../default/',
So, the function:
public function actionIndex(){
return $this->render(Yii::getAlias('#default_views') . 'site/index');
}
Created controller and tried to access it by url got an error like 404 Error
The page you are looking for could not be found.
Try checking the URL for errors, then hit the refresh button on your browser.
Used the fallowing procedure
//created route
'app-test-index' => array(
'test',
array(
'controller' => 'test',
'action' => 'index',
),
),
//controller
namespace App\Controller;
use Ppb\Controller\Action\AbstractAction,
Cube\Controller\Front,
Cube\View,
Cube\Validate\Url as UrlValidator,
Cube\Controller\Request,
Ppb\Service;
class Test extends AbstractAction
{
public function Index()
{
die('ok');
}
public function test()
{
die('ok');
}
}
How to create model view controller in PHPProbid
how to customize PHPProbid
Thanks
How to create a controller in PHPPROBID version 7.8
Step 1: Create a controller file in corresponding module
step 2: Edit the model Acl file in corresponding module
for example
a) Create a controller Test.php in module/App/src/App/Controller.
b) Add resources (Give permissions to user roles for the created controller) in
module/App/src/App/Model/Acl.php file
In our case you need to add the following lines
$test = new Permissions\Resource('Test');
$this->addResource($test);
$this->allow('Guest', 'Test');
It is important to note that the module/App/src/App/Model/Acl.php file will be replaced during phpprobid update
so you need to create a folder named mods in root(IF already exist no need to create).
Copy the file to mods folder with corresponding folder structure
In our example copy Acl.php to mods/module/App/src/App/Model folder.
Now you can access your controller
http://your_domain.com/index.php?module=app&controller=test&action=index