I have set pretty URL for yii2 advanced
at config/main.php
'urlManager' => [
'class'=>'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/' => 'site/index',
],
],
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
some controller
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
but query filter from gridView $searchModel still dirty, can I pretty params like some/action?name=jack&shift_id=1 without UserSearch[name]=jack ?
some/action?UserSearch%5Bname%5D=jack&UserSearch%5Bshift_id%5D=1&UserSearch%5Bmanager_id%5D=176
You should override formName() in your search model, to return empty string:
public function formName() {
return '';
}
Related
This code <?php echo Url::to(['/tasks/', 'view' => $task->id]);?> transforms into the url web/tasks?view=1 what code and where will transform output variants into the web/tasks/view/1?
Config File:
'urlManager' => [
# code...
'rules' => [
'tasks/view/<id:\d+>' => 'tasks/view',
],
Controller-Action
public function actionView($id) {
// $_GET or \Yii::$app->getRequest()->GET('id')
$id = ... int id
# code..
}
View File:
<?php echo Url::to(['/tasks/view', 'id' => $task->id]);?>
I have this before action inside my controller
public function beforeAction($action)
{
if ($action->id == 'delete-property') {
$this->enableCsrfValidation = false;
}
}
and this is the controller action
//Property Delete ID
public function actionDeleteProperty($id)
{
$id = Yii::$app->request->get('id');
echo $id;
}
This is the url manager
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:[\w\-]+>/<action:[\w\-]+>/<id:[\d]+>' => '<controller>/<action>'
],
],
When i visit http://localhost/hotel/delete-property/60d75e5842777110b81711b3 i get 404
Why am i getting the 404?
Your pattern for id parameter is [\d]+. \d matches any decimal digit, but your id is in hexadecimal so letters make it not match the [\d]+ pattern. You can use \w instead, and change your rule for example like this:
'<controller:[\w\-]+>/<action:[\w\-]+>/<id:[\w]+>' => '<controller>/<action>'
I have a problem with Yii export library. I just follow the documentation in this link: https://github.com/moonlandsoft/yii2-phpexcel , output have come out like encoding views.
my code view:
\moonland\phpexcel\Excel::export([
'isMultipleSheet' => true,
'models' => [
'sheet1' => Order::find()->all(),
], 'columns' => [
'sheet1' => ['id','phone','total'],
],
'headers' => [
'sheet1' => ['column1' => 'id','column2' => 'phone', 'column3' => 'total']
],
]);
You've got the xlsx file source directly embeded into your web page, because you didn't send proper headers. Your view template is fine but your controller action should look like this:
public function actionExport()
{
//set headers to prevent caching
$headers = \Yii::$app->response->headers;
$headers->set('Expires', 'Mon, 1 Apr 1974 05:00:00 GMT');
$headers->set('Last-Modified', gmdate("D,d M YH:i:s") . " GMT");
$headers->set('Cache-Control', 'no-cache, must-revalidate');
$headers->set('Pragma', 'no-cache');
//use renderPartial instead of render because we don't want to add layout
$content = $this->renderPartial('export');
//send content as attachment with filename my-export.xlsx and proper mime type
return \Yii::$app->response->sendContentAsFile(
$content,
'my-export.xlsx',
['mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
);
}
I have a problem with download excel file from site. I use kartik\export\ExportMenu; I add into view in script this :
<?php
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
$gridColumns = [
'order_number',
[
But it doesnt help. How could I fixed it?
public function actionIndex()
{
$searchModel = new OrderSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
There are three configurations that can help in case of timeouts but it's not guaranteed.
Options to set in ExportMenu widget configuration:
Large Files Linking
'stream' => false
Large Files Streaming
'stream' => false, // this will automatically save the file to a folder on web server
'streamAfterSave' => true, // this will stream the file to browser after its saved on the web folder
'deleteAfterSave' => true, // this will delete the saved web file after it is streamed to browser,
'target' => '_blank',
Batch Loading
'batchSize' => 10,
'target' => '_blank',
try increase the max_execution_time
<?php
ini_set('max_execution_time', 3600); //3600 seconds = 60 minutes
$gridColumns = [
'order_number',
[
I am working on Cakephp. In default.ctp i give a link like
<li><?= $this->Html->link('List',['controller' => 'Products', 'action' => 'index']) ?></li>
I also have a ProductsController.php .
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
class ProductsController extends AppController {
public function initialize(){
parent::initialize();
$this->loadcomponent('Flash');
}
public function index(){
$products = $this->Products->find('all');
$this->set(compact('products'));
}
But when i click on that link it give the error like
Error: WebrootController could not be found.
Error: Create the class WebrootController below in file: src/Controller/WebrootController.php
When click on toggle arguments it shows
object(Cake\Network\Request) {
params => [
'plugin' => null,
'controller' => 'Webroot',
'action' => 'products',
'_ext' => null,
'pass' => [],
'_matchedRoute' => '/:controller/:action/*',
'isAjax' => false
]
data => []
query => []
cookies => [
'__atuvc' => '1|21'
]
url => 'webroot/products/'
base => '/cakephp'
webroot => '/cakephp/'
here => '/cakephp/webroot/products/'
trustProxy => false
Please help me to solve this error.
Check if you have two .htaccess files present in your application root folder and in the webroot folder.
And make sure that an .htaccess override is allowed and that AllowOverride is set to All for the correct DocumentRoot
http://book.cakephp.org/3.0/en/installation.html#url-rewriting