This is the dynamic link from category table join to news table so i want to link in <li> to different page like allnational, allsports (these are the things in dropdown) function in home controller:
<ul class="dropdown-menu">
<?php if($category){
foreach($category as $c){
?>
<li><?php echo $c['category_name'];?></li>
<?php }} ?>
</ul>
just want to add link in above href
table scheme:
category_id: 1 , 2 , 3
category_name: national , international , sports
"category_id & category_name are column and its value listed above respectively"
Home controller:
public function allnational(){
$data['allnat'] = $this->newsmodel->getAllNational();
$this->load->view('allnational',$data);
}
public function allInternational(){
$data['allint'] = $this->newsmodel->getAllInternational();
$this->load->view('allinternational',$data);
}
if you can give suggestion what will be the model as well.
Note: model is already loaded.
Related
So I do have a table "words" and it has 2 columns "word" and "countofletters"
When I get them in the controller, how can I return them to the view based on the count, basically the view should contain something like:
4 letter words:
1- climb
2- Play
3 letter words:
1- put
2- cut
And so on..
Return from controller
You can send data to the view with compact instruction :
$yourDataFetchedFromDB = "";
return view('myviews.view', compact('yourDataFetchedFromDB'));
In your view
You can now access the value of $yourDataFetchedFromDB in your view as if you were in your controller.
Now you can use something like :
<ul>
#foreach($yourDataFetchedFromDB as $row)
<li>$row->word</li>
#endforeach
</ul>
And to use count columns you can use :
$yourDataFetchedFromDB[0]->countofletters
Full view code
<h2>{{ $yourDataFetchedFromDB[0]->countofletters }}</h2>
<ul>
#foreach($yourDataFetchedFromDB as $row)
<li>$row->word</li>
#endforeach
</ul>
Note : Obviously you should check if $yourDataFetchedFromDB[0] is not empty before using it
I have to build a solution which includes being able to drag and drop items from one list to others.
Basically I have a static list "subjects" which contains a few subjects and it could look like below.
<ul id="subjects" class="sortable_list connectedSortable">
<li class="ui-state-default">ID 1 - Item 1</li>
<li class="ui-state-default">ID 2 - Item 2</li>
<li class="ui-state-default">ID 3 - Item 3</li>
<li class="ui-state-default">ID 4 - Item 4</li>
<li class="ui-state-default">ID 5 - Item 5</li>
</ul>
Based on a variable $session which is an int I have to create i.e if $session=2 automatically two other sortable lists like below:
for ($x = 0; $x <= $session; $x++) {
echo "<ul id='sortable."$x".' class='sortable_list connectedSortable'>
</ul>";
}
What I want to do, is after dropping subjects from the #subjects I want to save in a php file the ID's of the items in each sortable list created automatically from the for loop and also the order of the files.
I want to use jquery-ui sortable, or if you have any suggestion please do so.
I would appreciate some ideas how to achieve this.
here's what you'll have to use: https://api.jqueryui.com/sortable/#method-serialize
Choose the correct IDs eg ( change id='sortable."$x"' to sortable_"$x" in your code and what you'll get is a string of ordered IDs in the format sortable[]=1&sortable[]=5&sortable[]=2 .
Then you can split this string and manipulate it and use it accordingly.
I get this data through one controller in a list in my view files,and i also want to show in every page a different meta title. How it is Possible ?
View
<?php
$data = "";
foreach($items_data as $row){
$data .= '<li class="list-group-item">
<a href="'.base_url("hotels/ls/".$row->item_id).'">'.$row->item_name.'<span class="fa fa-angle-double-right pull-right" style=""></span>
</li>';
}
echo $data;
?>
Suppose i got four items like
Books
Pens
Computers
All of my items are showing these urls which is pretty good.
www.xyz.com/1
www.xyz.com/2
www.xyz.com/3
But i want to show my item names in every url. along with different meta tag title name.
Now when i click on any listed items my url will show something like these
This is possible or not , Because above list are getting from database.
www.xyz.com/computers
www.xyz.com/Books
www.xyz.com/Pens
Here is my controller which is fetching data from database.
Controller
function index() {
$data['items_data'] = $this->Visa_mdl->get_items_name();
$data['title'] = "Hotels";
$this->load->view('include/header');
$this->load->view('hotels/visa',$data);
$this->load->view('include/footer');
}
This Controller is Linked to other Pages.
function ls($item_name = NULL) {
$data['title'] = "Company Lists";
$result = $this->Visa_mdl->get_items_company_list($item_name);
$result1 = $this->Visa_mdl->get_items_name_in_dash($item_name);
$data['items_data'] = $this->Visa_mdl->get_items_name();
// $data['items_company_data'] = $this->Visa_mdl->get_items_company_list($id);
$this->load->view('include/header',$data);
$this->load->view('hotels/dashboard',$data);
$this->load->view('include/footer');
}
Instead of this:
<a href="'.base_url("hotels/ls/".$row->item_id).'">'.$row->item_name.'<span class="fa fa-angle-double-right pull-right" style=""></span>
try
<a href="'.base_url("hotels/ls/".$row->item_name).'">'.$row->item_name.'<span class="fa fa-angle-double-right pull-right" style=""></span>
and try again.
In your code you have passed $row->item_id which shows item id in url, instead of that pass $row->item_name then it will show item name in url.
I want to build a menu from an array in Laravel. What I'm currently doing is putting the array in a view
$menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
and then looping through it to generate the menu:
<section>
<!-- Left Nav Section -->
<ul class="left">
<li class="divider"></li>
#foreach($menu as $key => $nav)
<li class="has-dropdown">
{{ $key }}
<ul class="dropdown">
#foreach($nav as $subnav)
<li>
{{ $subnav }}
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
</section>
Is there any other way that I can achieve the same result without putting the data in the view?
I also tried creating a constructor function in the controller:
public function __construct() {
$menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
return $menu;
}
But I guess that is not how it works. I appreciate any ideas on how I can go about this. Thanks in advance
View composers to the rescue!
They are executed every time before a view is rendered, so you can use this to pass standard data to them.
If you're using controller layouts you can bind data to the layout from within the constructor. Just make sure you call the parent constructor first so that the layout is instantiated properly.
public function __construct()
{
parent::__construct();
$this->layout->menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
}
That will bind a $menu variable to the layout, and will also be available to any nested views that are used with Blades #include.
Have a look at view composers:
http://www.laravel.com/docs/views#view-composers
In my model i have:
* #method Doctrine_Collection getComments() Returns the current record's "Comments" collection
Default if i generated admin then this isn't showing in list.
If is in generator.yml :
config:
actions: ~
fields: ~
list:
display: [id, title, comments]
filter: ~
form: ~
edit: ~
new: ~
Then this show me
<pre> Doctrine_Collection data : Array( ) </pre>
instead of list of comments.
I know - i can get files from cache and showing this, but maybe this is possible only with generator.yml ?
For example if i have relation one to many then this showing me this name.
I dont want use cache for this!
thanks!
you can use a function for your problem.
For example, in my generator.yml
list:
display: [id, description, public, nbQuestions]
nbQuestions is a function in Object.class.php
public function getNbQuestions() {
return $this->getQuestion()->count();
}
The admin generator will automatically call the "getYouField" Method in the object class. So you can describe a function which return a long string for you doctrine collection.
There is an other way than only displaying a count.
You can add a partial in your generator.yml:
list:
display: [id, description, public, _comments]
Then in your partial (_comments.php), you can call the relation and display what ever you want (add style, other infos, etc ..):
<?php
// note that you will need to change the $object
echo $object->getComments()->count();
?>
In an other way, it could be usefull to have all comments listed in the edit view. In your generator.yml:
form:
# don't forget to add others fields
display: [_comments]
And then in your partial:
<ul>
<?php foreach($form->getObject()->getComments() as $comment): ?>
<li><?php echo $comment->getBody() ?></li>
<?php endforeach; ?>
</ul>
And if you want to combine both in the same partial (don't forget to rename $object):
<?php if(isset($form)): ?>
<ul>
<?php foreach($form->getObject()->getComments() as $comment): ?>
<li><?php echo $comment->getBody() ?></li>
<?php endforeach; ?>
</ul>
<?php elseif(isset($object)): ?>
<?php
// note that you will need to change the $object
echo $object->getComments()->count();
?>
<?php endif; ?>