This is a source code of nav bar made using PHP framework CodeIgniter.I didn't understand login behind nav url of "Bulk Conversion" and "Login" which is given using site_url instead of <a href = "bulk_conversion.php"> and <a href = "login.php">. How nav bar code works here?
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation" class="{{ $_nav === 'batch' ? 'active' : '' }}">Bulk Conversion</li>
<li role="presentation">Login</li>
</ul>
</nav>
CodeIgniter is an object-oriented MVC framework. For the most part you don't make calls to .php files by name. Instead, CodeIgniter uses a segment-based approach to URLs with a one-to-one relationship between a URL string and its corresponding controller/method and optionally, parameters. Any URI segments after the first two are considered parameters (variables) passed to the controller's method. Find a better explanation of what I'm trying to explain in the Documentation.
site_url is a CodeIgniter helper function that will construct a full URL from a URI string. So the call to site_url('batch') for a website on example.com will produce the string http://example.com/batch. This will result in the index() method of the controller Batch being executed.
The call site_url('admin') works the same except the Admin controller is being called.
Clear as mud?
Related
Hi and I'm terribly sorry for asking such question.
I'm quite catching up on Laravel, maybe 30% smarter than before but I'm stuck on this kind of scenario.
How do I call a blade with all parameters passed to its controller without refreshing the page.
Here's my folder structure (I will not place all just controller, pages)
Folrder Structure
Now, I'm in let's say dashboard.blade.php
In the Side bar of my dashboard I want to go to a link
<li class="nav-item">
<a href="{{url('/get-greeting/{id}/{user}')}}" class="nav-link get-greeting">
<i class="nav-icon fas fa-table"></i>
<p>
Requested Son
<span class="right badge badge-danger side-span requested-span"></span>
</p>
</a>
</li>
Route will be
Route::any('/get-greeting/{id}/{user}', 'DefaultController#pullGreeting')->name('getgreeting');
Controller will be
public function pullGreeting($id, $user){
$userName = User::activeUser($user);
$defaultarray = array( 'greetingLogs' => recordLogs::pullgreetings($user) );
return view('pages/department1/greetings',$defaultarray);
}
When I click it, it refreshes the page. Anyone, can you help me and pinpoint where am I doing wrong so I can make it not refreshing the page but instead changing the blade dynamically?
Does this matter?
return view('pages/department1/greetings',$defaultarray);
or
return view('pages.department1.greetings',$defaultarray);
PHP is a server-side programming language therefore any changes to the view will require a full page refresh.
Without the use of Javascript, achieving a part page refresh would require the use of an old school technique called Frames.
You could redesign your application to render HTML via different endpoints and have a Javascript powered frontend that calls to those endpoints.
You could easily achieve through the use of JS Libraries such as React or JQuery.
I am working on Laravel 5.4
I have created a menu, in which three tabs Home, about and contact. When I click on Home then it should be on home page. When click on about, it should be on about page....
web.php:
<?php
Route::get('/', function()
{
return View('method1.home');
});
Route::get('about', function()
{
return View('method1.about');
});
**method1 is folder in resources\views**
home.blade.php:
#extends('method1.dashboard')
#section('content')
<h1>This is home page</h1>
#endsection
about.blade.php is:
#extends('method1.dashboard')
#section('content')
<h1>This is about page</h1>
#endsection
dashboard.blade.php is:
#include('method1.includes.menu-header')
menu-header.blade.php is:
<li class="active"> Home</li>
<li> About</li>
But when I click on home or about page. It shows Page is not found.
My laravel projet folder name is admin_laravel. When I run http://localhost/admin_laravel/ then it shows home page and when run http://localhost/admin_laravel/about it shows about page.
But when I click on about menu button then in browser shows link http://localhost/about. Means it is not going with http://localhost/admin_laravel/about and page is not showing.
You are missing something there, For a quick fix you can do this:
<li class="active"> Home</li>
<li> About</li>
You can also give route name and go with route method:
Route::get('about', function()
{
return View('method1.about');
})->name('about');
Then:
<li> About</li>
Here is the details: https://laravel.com/docs/5.2/helpers#method-route
You're hard-coding your URLs. When you have <li>About</li> you're telling your browser to go to the about path from the root of the domain (which is what happens when you prefix your URL with /), which in this case is http://localhost/.
There's a few things you should be doing. First, set the base URL for your project, you can update APP_URL in your .env file
APP_URL=http://localhost/admin_laravel
or the url option in config/app.php.
'url' => env('APP_URL', 'http://localhost/admin_laravel'),
Secondly, when generating URLs in Laravel there are quite a few options. If you're not using named routes, then you should use the url helper method to generate your URLs:
<li>About</li>
That will make sure that your URL is based at the root of your project, rather than the root of the domain. When you use url in conjunction with the correct setting as described above, your URLs will be generated correctly.
<li>SERVICES</li>
<li>ABOUT</li>
<li>CONTACT</li>
I'm using CodeIgniter and this code was in a different controller. suppose http://localhost/defctrl/function1
I want to return to my homepage "maine/home" in a specific div when you click on the list but the above code doesn't work. neither ../maine/home#services.
How can I solve this problem?
if it's on the same page you can use
<li><a href="#services"
if another page
<li><a href="<?php echo base_url() ?>{route or controller name}#services"
Make sure URL helper is loaded and site load with index.php
i am new to codeigniter framework. i am having problem with href link. in my home page i have some menu, that goes to different page. for example in normal php if i want to go Sell Books page then i just put sellBook.php in href link. now in codeigniter how can i do this. do i need write something in controller ?
<li >Home </li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
as per MVC pattern each of your url is a controller so:
if you, for example, want to link to
http://www.site.com/users
so the controller will look like:
class Users extends CI_Controller{
function index(){
//do somenthing here
}
function list(){
//list your users
}
}
then in your views linking to that controller is simple:
this will link to your users controller and index() method
this will link to your users controller and list() method
the site_url(); method will helps you finding the right link both if
you are using index.php or not in your urls
<a href="<?php echo base_url() ?>controller_name/function_name">
If you are using mod_rewrite to remove the index.php from the URL, you can write your URL as href="/sellbook" otherwise you will have to include it, such as href="/index.php/sellbook".
This assumes, of course, that you have a properly configured route name sellbook. See http://ellislab.com/codeigniter/user-guide/general/routing.html for details on how to achieve this.
If the links are to other pages on your site, then I think your best bet will be to use the url helper, assuming you're using the standard seo friendly format and not query strings. This way, you don't have to take into consideration whether you'll be using .htaccess or not. For example:
echo anchor('your_controller_name/your_function_name/param_1/param_2', 'Sell Books', 'title="Sell Books"');
// or for your home page
echo anchor('/', 'Home', "title='Home'");
If it's an external link, you can use the same function or just a plain html tag:
echo anchor('http://google.com', 'Google Me', 'title="Google Me"');
// OR
<a href="http://google.com" title="Google Me" >Google Me</a>
Note: make sure you load your url_helper in your controller if you'll be using the anchor function:
$this->load->helper('url')
// or add to autoload.php
You can also do it the way #sbaaaang suggested.
Account Details
You can use like this
<li>Home</li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
//use
site_url in link with controller name and method
and
$this->load->view('page_name');
I need to build some ajax tabs with CodeIgniter. The problem I am having is that I need a lot of information stored in 1 tab, and the info differs in each tab so I can not use a template HTML and just populate the data with different values. The designer that provided the markup styled it so that each html part is hidden.
So my question is how should I do it? Get the values i need for each ajax call and populate each tab by context or should I load individual pages for each tab ..so the html and the data are on a different page. I tried to do this in CodeIgniter, but I could not manage to do it in a MVC context.
solution 1. Load all data via the Codeigniter controller and show/hide tabs with Javascript.
When JS is disabled: show all data on one page
solution 2. make a call to the server via ajax for each click that exposes a tab, and then call the controller.
To be able to call a controller from Javascript you need the base url:
http://www.jigniter.com/use-your-site-url-or-base-url-in-javascript-functions/comment-page-1/#comment-654
$.getJSON(CI.base_url + 'controller/method/', function(data) {
// ...
}
or use $.ajax for complexer stuff.
When JS is disabled: each click loads a new view.
First build this without JS, then overlay it.
You can load all the information directly from the controller and pass data to the main view.
Codeigniter provide the 3rd parameter for the view to do this:
$string = $this->load->view('myfile', '', true);
in this case you have all the data of the myfile into the $string.
You can put the data into a separated view from the template and then load it.
For example:
$info_tab['first_tab'] = $this->load->view('first_tab_content', '', true);
$info_tab['second_tab'] = $this->load->view('second_tab_content', '', true);
$this->load->view('html_template',$info_tab);
in this way you have two new variables in the view.
The best way to do this is load in partials views ( you load a partial view by passing false as a third view param which gives you a string ) with conditional statements. Tab1 might need to meet 0 conditions, tab2 might need to meet 2 conditions and so on. The best bet might be to use the HMVC plugin.
<ul class="tabs">
<li>Tab One</li>
<li>Tab Two</li>
<li>Tab Three</li>
</ul>
-
<div id="tab-one" class="tab-content">
<?php echo Modules::run('module/tab_one'); ?>
</div>
<div id="tab-two" class="tab-content">
<?php echo Modules::run('module/tab_two'); ?>
</div>
<div id="tab-three" class="tab-content">
<?php echo Modules::run('module/tab_three'); ?>
</div>
-
public function tab_one(){
$this->load->view('module/partials/view_one', array(), false)
}
-
view_one
PHP
if(condition_is_meet):
// do something
PHP
else:
//do something else
PHP
endif;