A
A
Alexander2016-11-18 13:23:23
Yii
Alexander, 2016-11-18 13:23:23

How to generate page transition links on request?

I decided to make a course on yii2. look into it at the same time. library site type
There is a piece of code in the widget view that creates a list of links in alphabetical order...

echo 'По авторам: ';
    $abc = array();
    $j=0;
    foreach (range(chr(0xC0), chr(0xDF)) as $b){
        $abc[] = iconv('CP1251', 'UTF-8', $b);
        echo(' '.'<a href="#">'.$abc[$j].' '.'</a>'); $j++;}
    echo '<a href="#">'.' '.'[A-Z]'.'</a>';
        echo '<br>';

So, how to make it so that, by clicking on a letter, there was a transition to a page with a list of the contents of everything that found this letter in the database?
how and what to insert in href="" ? I understand that in quotes should send a request to the page controller which will redirect to a unique page. You also need to organize the transfer to GET / POST and the selection from the database with these parameters. I'm confused. Help - what to enter where. The selection should take place in the model as in Japan and also pass data to the controller ....
and how to generate these pages on request? (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-11-18
@koshalex

Yes, your reasoning is basically correct.
You must create a controller action to select authors by letter and in the link form the URL to this action with the GET parameter - the selected letter.
and controller

public actionAuthors($char = null) 
{
$model = Authors::find();
if($char) {
$model->where(['like', 'name', '%'.$char, false])
}
return $this->render('view', ['model' => $model]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question