I'm trying to add a view just a simple contact page, I already have other views.
Here's what I've done so far:
added 'contact' in my routes file here
$route['^(?!/|site|ajax|gallery|contact).*'] = "site/view/$1";
added contact.php to my application/views folder
added contact() to my site controller (whole controller here http://pastebin.com/CCjjrV8R)
function contact() {
$this->load->model('Site_model');
$this->load->view('contact');
}
When I visit the correct url for the view (domain.com/contact), I get a page with partial content and "404" in the
Can anyone see a problem? This is very puzzling.
I don’t think you need the view part of the URL in the route?
Related
How can I show a view from a controller? Here is my code:
This is my controller.php file in /var/www/html/application/controllers/controller.php
public function __construct($controller) {
if(!this->controller) {
//show page from: /var/www/html/application/views/404.php
}
}
As far as i can understand from controller path, this is Codeigniter PHP Framework.
If so, you can load 404.php with code below:
$this->load->view('404');
Also there is a function named show_404() that trigers 404 error and loads corresponding view.
I strongly recommend you to read Codeigniter Documentation from beginning.
When I download project in https://www.codeigniter.com/user_guide/installation/downloads.html
CodeIgniter v2.2.0
When I run http://localhost/qldv, I get result as welcome page of codeigniter, but when I register in routes.php with route
$route['admin/welcome'] = 'welcome';
When I go to web with link: http://localhost/qldv/admin/welcome
I don't get welcome page. Result is
Object not found!
Please help me. Thanks
If you don't disable having to put index.php in the URL (using an htaccess file), this route won't work. This would: http://localhost/qldv/index.php/admin/welcome
To disable index.php in the url look at this question:
CodeIgniter removing index.php from url
Put this code in your Welcome Controller.
public function admin()
{
$this->load->view('welcome_message');
}
Put this code in your Welcome Controller.public function admin()
{
$this->load->view('welcome_message');
}
I am having troubles with connecting one of my routes to its associate controller function.
Routes file
Route::get('/transaction/export','TransactionController#exporter');
Controller and Function
class TransactionController extends Controller
{
public function exporter(){
dd("works");//-->Not seen :(
return view('admin.transactionExport');
}
}
Link in view
Export
When clicking on the link, the address bar in the browser shows the expected url '/transaction/export', but unfortunately it shows me a blank page. It is as though the function in the Routes file does not link to the proper controller. I have over 30 successful links in this site, and have no idea why this is failing on me right now.
Would appreciate the help. Please inform me if more information is needed to solve this.
Change your route to match the controller:
Route::get('/transaction/exporter', 'TransactionController#exporter');
Your previous route wasn't matching 'exporter'.
i want to put login form in navigation(template) so that it will be shown in all the pages.
and will check username and password in database without going to other pages. if failed, an error will be shown in the nav and if success, the page will be reloaded again with specific costomizations. please tell me how with code and details.
i have these parts in my template:
header
nav
footer
and content that will be added in current controller
i wanna do this in each controller:
$this->load->view('templates/header');
$this->load->view('templates/nav');
$this->load->view('related_view');
$this->load->view('templates/footer');
but my navigation should contain a login form which will not go to another page by submitting.
I usually do something like this:
<?php
$this->load->view('templates/header');
if ($this->user_model->isLoggedIn())
{
// Logged-in users should see this view
$this->load->view('templates/nav-registered');
}
else
{
// Guests should see this
$this->load->view('templates/nav-guest');
}
$this->load->view('related_view');
$this->load->view('templates/footer');
You'll thank yourself if you override the Loader class to grab your header/footer for you automatically, not having to code this in EVERY controller method. Just a thought..
use session to check loged user, and put this on the nav view, but first make sure you have session loaded from auload or from your controller
if($this->session->userdata('user_loged')){
//code to put some navigation when use is loged
}else{
//code to put login form
}
The solution I found is to extend the Controller class. So In this case we should make an extended controller (for example MY_Controller) and put the dynamic action (here authentication) in it as a method.
Then we should extend this self-made controller in each of our controllers , so authentication in the template would be simply handled.
I am using codeigniter for a project. I set controller A as my default controller in routes.php. So in this controller A it will load my home page.
If I want to access another view from the homepage for example about or contact, how do I go about doing it??
Example:
<a href="http://yoursite.com/yourcontroller/yourfunction">About Page
Now you have yourcontroller that has the yourfunction in it, from within this function you can load the view for about page, like:
function yourfunction() {
$this->load->view('your_about_view_page_name");
}
And that shall work. Hope it helps