Thinkphp cross-Controller template output issues

Source: Internet
Author: User
Tags urlencode
Describe the problem first
Search under Home Index and assign the search results to the show template output under the show module.


Class Indexaction extends Action {//This is the index module
Public Function index () {
echo session ("UID");
$this->display ();
}
Public Function Dosearch () {//Fuzzy query
$user = M (' user ');
$key = $_request[' Keysearch ');
$where [' username '] = $key;
$where [' username '] = array ("Like", Array ("% $key", "$key%"));
Import (' ORG. Util.page ');//Import page-out class
$data = $user->where ($where)->select ();
$count = $user->where ($where)->count ();//number of conditional queries
$Page = new Page ($count, 3);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page
foreach ($where as $key = = $val) {
if (!is_array ($val)) {
$Page->parameter. = "$key =". UrlEncode ($val). ' & ';
}
}

$show = $Page->show ();//pagination display output
$mohulist = $user->where ($where)->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
$this->assign (' users ', $mohulist);

$this->assign (' page ', $show);//Assignment Paging output

$this->display (' show/show '); Assign the search results to the show model output under the show module

}

But once the search form address is submitted, it becomes http://www.tanss.com/alumni/index.php/Index/dosearch.
In fact, this seems to be no problem, but I need to work on the results of this search, such as messages, check the details and other operations, so when I write a message in the Show module, view details and other methods will be reported illegal operation, such as the problem how to deal with it,


Reply to discussion (solution)

Post an error to see

Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112


Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112




Form submitted by the address to see



Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112




Form submitted by the address to see








Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112




Form submitted by the address to see






Replace with action= "{: U (' Show/domessage ')}" try





Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112




Form submitted by the address to see






Replace with action= "{: U (' Show/domessage ')}" try




Yes, well, that's fine, thank you first, huh?
What I do not understand is that if the query is executed under the current control, but the template output query results under the other controller, how can
Http://www.tanss.com/alumni/index.php/Index/dosearch changed to Http://www.tanss.com/alumni/index.php/Show/show. Because of this, you can write a new method directly under show without using the U method.








Post an error to see


This is a new way of writing under show.
Class Showaction extends action{

Public function Show () {

$this->display ();

}

Public Function Domessage () {
$message = M (' message ');
$data [' content '] = $_post[' message '];
$data [' time '] = Date (' y-m-d h:i:s ', Time ());
$message->add ($data);
$this->redirect (' show/show ');
}

}

Error after submission
Illegal operation: Domessage
Wrong location
file:d:\phpdemo\alumni\thinkphp\common\functions.php line:112




Form submitted by the address to see






Replace with action= "{: U (' Show/domessage ')}" try




Yes, well, that's fine, thank you first, huh?
What I do not understand is that if the query is executed under the current control, but the template output query results under the other controller, how can
Http://www.tanss.com/alumni/index.php/Index/dosearch changed to Http://www.tanss.com/alumni/index.php/Show/show. Because of this, you can write a new method directly under show without using the U method.




This is the way you are in the index of the Dosearch method with display (' Show/show '), when you go to the Show template, but your URL is still original. or index. At this time your __url__/message is looking for index/message. (You can write a message method to verify it in index). The solution is that you do not use display in the Dosearch of index, with redirect (' Show/show ')

Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay

Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay



Well, if you use redirect, assign is really useless, how about this redirect parameter? Redirect (Show/show) is the Show method under Show controller?


Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay



Well, if you use redirect, assign is really useless, how about this redirect parameter? Redirect (Show/show) is the Show method under Show controller?



Show controller under Show method redirect (' Show/show ', Array (' users ' = $mohulist, ' page ' = + $show)) and then in the Show method with $mohulist = $_get[' Mohulist ']; $page = $_get[' page '];

Write the wrong show is $mohulist = $_get[' users '; $show = $_get[' page '];



Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay



Well, if you use redirect, assign is really useless, how about this redirect parameter? Redirect (Show/show) is the Show method under Show controller?



Show controller under Show method redirect (' Show/show ', Array (' users ' = $mohulist, ' page ' = + $show)) and then in the Show method with $mohulist = $_get[' Mohulist ']; $page = $_get[' page '];




Indexx below Dosearch method
Public Function Dosearch () {//Fuzzy query
$user = M (' user ');
$key = $_request[' Keysearch ');
$where [' username '] = $key;
$where [' username '] = array ("Like", Array ("% $key", "$key%"));
Import (' ORG. Util.page ');//Import page-out class
$data = $user->where ($where)->select ();
$count = $user->where ($where)->count ();//number of conditional queries
$Page = new Page ($count, 3);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page


foreach ($where as $key = = $val) {
if (!is_array ($val)) {
$Page->parameter. = "$key =". UrlEncode ($val). ' & ';
}
}

$show = $Page->show ();//pagination display output
$mohulist = $user->where ($where)->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
$this->assign (' users ', $mohulist);
$this->assign (' page ', $show);//Assignment Paging output
$this->display (' show/show ');
$this->redirect (' show/show ', Array (' users ' and ' = ' $mohulist, ' page ' + $show));
}

Show method below

Public function Show () {
$mohulist = $_get[' mohulist ');
$page = $_get[' page '];
$this->display ();
}

Error not Found after submitting query

The requested url/alumni/index.php/show/show/users//page/+1+�记�+1/1+页++++++++++.html was wasn't found on this Server.
In addition I added the header in the controller (' Content-type:text/hmtl;charset=utf-8 '); Why does the error still appear garbled AH




Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay



Well, if you use redirect, assign is really useless, how about this redirect parameter? Redirect (Show/show) is the Show method under Show controller?



Show controller under Show method redirect (' Show/show ', Array (' users ' = $mohulist, ' page ' = + $show)) and then in the Show method with $mohulist = $_get[' Mohulist ']; $page = $_get[' page '];




Indexx below Dosearch method
Public Function Dosearch () {//Fuzzy query
$user = M (' user ');
$key = $_request[' Keysearch ');
$where [' username '] = $key;
$where [' username '] = array ("Like", Array ("% $key", "$key%"));
Import (' ORG. Util.page ');//Import page-out class
$data = $user->where ($where)->select ();
$count = $user->where ($where)->count ();//number of conditional queries
$Page = new Page ($count, 3);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page


foreach ($where as $key = = $val) {
if (!is_array ($val)) {
$Page->parameter. = "$key =". UrlEncode ($val). ' & ';
}
}

$show = $Page->show ();//pagination display output
$mohulist = $user->where ($where)->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
$this->assign (' users ', $mohulist);
$this->assign (' page ', $show);//Assignment Paging output
$this->display (' show/show ');
$this->redirect (' show/show ', Array (' users ' and ' = ' $mohulist, ' page ' + $show));
}

Show method below

Public function Show () {
$mohulist = $_get[' mohulist ');
$page = $_get[' page '];
$this->display ();
}

Error not Found after submitting query

The requested url/alumni/index.php/show/show/users//page/+1+�记�+1/1+页++++++++++.html was wasn't found on this Server.
In addition I added the header in the controller (' Content-type:text/hmtl;charset=utf-8 '); Why does the error still appear garbled AH



Yes, well, as you changed, it was the same mistake. And there are query results when the error is empty query or query no results will not report errors




Assign might not work. You need to pass the redirect parameter to Show/show again by the Show method assign again Diaplay



Well, if you use redirect, assign is really useless, how about this redirect parameter? Redirect (Show/show) is the Show method under Show controller?



Show controller under Show method redirect (' Show/show ', Array (' users ' = $mohulist, ' page ' = + $show)) and then in the Show method with $mohulist = $_get[' Mohulist ']; $page = $_get[' page '];




Indexx below Dosearch method
Public Function Dosearch () {//Fuzzy query
$user = M (' user ');
$key = $_request[' Keysearch ');
$where [' username '] = $key;
$where [' username '] = array ("Like", Array ("% $key", "$key%"));
Import (' ORG. Util.page ');//Import page-out class
$data = $user->where ($where)->select ();
$count = $user->where ($where)->count ();//number of conditional queries
$Page = new Page ($count, 3);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page


foreach ($where as $key = = $val) {
if (!is_array ($val)) {
$Page->parameter. = "$key =". UrlEncode ($val). ' & ';
}
}

$show = $Page->show ();//pagination display output
$mohulist = $user->where ($where)->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
$this->assign (' users ', $mohulist);
$this->assign (' page ', $show);//Assignment Paging output
$this->display (' show/show ');
$this->redirect (' show/show ', Array (' users ' and ' = ' $mohulist, ' page ' + $show));
}

Show method below

Public function Show () {
$mohulist = $_get[' mohulist ');
$page = $_get[' page '];
$this->display ();
}

Error not Found after submitting query

The requested url/alumni/index.php/show/show/users//page/+1+�记�+1/1+页++++++++++.html was wasn't found on this Server.
In addition I added the header in the controller (' Content-type:text/hmtl;charset=utf-8 '); Why does the error still appear garbled AH



Because your parameter $show is not a simple string or array parameter, it should be an object to look at. Suggest you still in action with U method, U method originally support Cross controller, why not?

Force to use the $show serialized out the past and then deserialized back. But it's a very anti-human operation.

Force to use the $show serialized out the past and then deserialized back. But it's a very anti-human operation.



Yes, yes, well, I'm just learning PHP. I want to know how to deal with the controller problem, you can use the U method it's hard for you, man.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.