<?php echo $users->links('view.name'); ?>
If I specify this view in laravel-4, what will be the code inside it? I can't find an example in the docs. Any example please?
according to this http://laravel.com/docs/pagination
If you use the paginator like this
<?php echo $users->links(); ?>
Laravel will use the default view which is defined inside app/config/view.php as
'pagination' => 'pagination::slider-3',
With this default option, your pagination will use the Illuminate/Pagination/views/slider-3.php view,
which is the following:
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pagination">
<?php echo $presenter->render(); ?>
</ul>
<?php endif; ?>
You can define your own view, and then use inside it the $paginator object to format it according to your needs.
You can see an example here.
Related
I want to link this anchor to the method "newInvoice()" specified in controller
<?php $this->load->helper('url'); ?>
<li><?php echo anchor('new_invoice_c/newInvoice', 'New Invoice'); ?></a> </li>
controller
class New_invoice_c extends CI_Controller {
public function newInvoice()
{
$this->load->view('new_invoice');
}
}
The problem is that the anchor() is not returning the full string (when i check it via "view page source) but only upto first paraemeter i.e. method name as follows.
<a href="http://localhost/cibs/index.php/new_invoice_c">
When I renamed my mehtod to index() the view is loaded successfully.
It may seem naive but here is what i tried
echo anchor(site_url('new_invoice_c.php/newInvoice'), 'New Invoice');
echo anchor('new_invoice_c.php/newInvoice', 'New Invoice');
beside that I refresh the page after clearing chache but still I am unable to figure it out.
Change this
<li><?php echo anchor('new_invoice_c/newInvoice', 'New Invoice'); ?></a> </li>
to
<li><?php echo anchor('new_invoice_c/newinvoice', 'New Invoice'); ?></li>
You added </a> where it was not required
It should be like this:
<?php echo anchor('new_invoice_c/newinvoice', 'New Invoice');?>
Here is official Codeigniter user guide, check it.
https://codeigniter.com/userguide3/helpers/url_helper.html
change it
echo anchor(site_url('new_invoice_c.php/newInvoice'), 'New Invoice');
to
echo anchor(base_url('new_invoice_c.php/newInvoice'), 'New Invoice');
I was doing a silly mistake while doing all this. I was editing the other file while accessing the anchor from another file. Every thing was ok except the source file. any how, thanks to all for answering <li><?php echo anchor('new_invoice_c', 'New Invoice') ?> </li>
I'm a begginer in Yii2 framework.
I work on a forum :
In the forum/posts method, there is a list of posts about the topic.
Each Post have a score which I want up and down in AJAX.
In my view posts.php, I open a Pjax block :
<?php Pjax::begin(); ?>
Votes : <?= $val['score'] ?>
<?= Html::a('+', ['/post/voteup','id'=>$val['id']]) ?>
<?= Html::a('-', ['/post/votedown','id'=>$val['id']]) ?>
<?php Pjax::end(); ?>
In my PostController :
public function actionVoteup($id){
//Update request
$postRepo=new PostRepository();
$postRepo->vote('plus', "id=$id");
$post=$postRepo->getAll("id=$id");
return $this->renderAjax('vote', ['id'=>$id, 'score'=>$post[0]['score']]);
}
You can see I return the Vote.php view in Ajax, same code Pjax.
<?php Pjax::begin(); ?>
Votes : <?= $score ?>
<?= Html::a('+', ['/post/voteup','id'=>$id]) ?>
<?= Html::a('-', ['/post/votedown','id'=>$id]) ?>
<?php Pjax::end(); ?>
The update request is OK but I have some problems/questions :
Ex : I want to up the 2nd post score, I click, OK, I click a second time, the part of view which is refresh is the 1st Post score (but in database, it's the good score updated).
I think the problem is about my part of view that I return in my actionVoteup().
Should I return forum/posts or post/vote ?
When I click in the link, my URL is : post/voteup ; how can I return in the original URL forum/posts ?
I don't really understand how works Pjax, and I didn't find good examples about its utilisation.
Thanks for your replies :)
You need to add 'enablePushState' => false in Pjax attribute.
Like as
<?php Pjax::begin(['enablePushState' => false]); ?>
For more info. Visit this Demo
I am using a Yii2 advanced app. The back end is fine, but I'm having a problem when I try to create a page (e.g., abc.php) in the front end/views folder, and then try to use a bootstrap ActiveForm class. For example:
<?php
use yii\helpers\Html;
use bootstrap\ActiveForm;
?>
<div class="client-vehicle-info-form">
<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
<?php ActiveForm::end(); ?>
</div>
Here is the error I am getting:
Fatal error: Class 'bootstrap\ActiveForm' not found in C:\xampp\htdocs\MyApp\frontend\views\abc.php on line 10
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; ?>
What's the quickest and easiest way to add the "active" class to a link, so it can be styled? I'm developing an app in CI, and I'd like a quick easy way to do this automatically.
jQuery is an option too...
You should really be using the CodeIgniter URI Class to do this instead of the $_SERVER['REQUEST_URI']
$this->uri->uri_string()
if ( $this->uri->uri_string() == '/contact' )
^^ that is the preferred way to do things due to some complexities that can happen with codeigniter's routing features
Depends on how you're outputting your link HTML.
If you're using the URL Helper module, then you can call the anchor() function to create your links, and pass it an array of attributes as the third parameter, ie:
$this->load->helper('url');
echo anchor('url/path', 'Click here', array('class' => 'active'));
If you're just outputting the HTML manually in your templates/views, obviously you can just create the class attribute yourself in the HTML.
If you have a lot of navigation items you can do it this way (very simplified)...
<ul>
<li<?= if ( $_SERVER['REQUEST_URI'] == '/contact' ): ?> id="active"<?php endif; ?>>contact</li>
</ul>
You'll have to edit it for your needs...
If you don't have that many nav items an easier way is to give each page a body id and then use css to make it active.
<style type="text/css">
body#contact #contact-nav { font-weight:bold; }
</style>
<body id="contact">
<ul id="navigation">
<li id="contact-nav">contact</li>
</ul>
You can do this way by creating helper with following
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('active_link'))
{
function active_link($controller)
{
$CI =& get_instance();
$class = $CI->router->fetch_class();
return ($class == $controller) ? 'active' : '';
}
}
then apply it in menu view
<li class="<?php echo active_link('services'); ?>">Services</li>
To adding active class (class=”active”) to a link , I’ve done it by doing this:
In view
<ul class="nav nav-tabs">
<li id="button_home" class='<?php echo $home;?>'><?php echo anchor('pages/index','Home');?></li>
<li id="button_about" class='<?php echo $about;?>'><?php echo anchor('pages/about','About')?></li>
</ul>
In controller
$data['home']="active";
Maybe it's not your solution. but it works for me.