我如何“修复”php工匠?

时间:2015-09-14 21:01:09

标签: php laravel artisan

我正在使用Laravel 5.每当我输入

php artisan tinker

我得到预期的输出前面有一个字母c:

cPsy Shell v0.5.2 (PHP 5.6.10-1+deb.sury.org~trusty+1 — cli) by Justin Hileman

当我输入php artisan

时也会发生同样的情况

我得到的第一行是:

cLaravel Framework version 5.1.16 (LTS)

不知何故,这封信显示在我的所有观点上,所以搞乱了我的项目。当我点击“查看页面来源”时,我在“<!DOCTYPE html>”之前看到字母“c”,但我无法在任何文件中找到它。

3 个答案:

答案 0 :(得分:5)

尝试这个技巧:

输入您选择的控制器方法此代码:

django.contrib.admin.util

如果一切顺利,PHP将无法发送标头,并在错误消息中写入文件和输出(“c”)开始的行。

注意:如果您正在使用输出缓冲,则无法使用此功能。

答案 1 :(得分:1)

您可能会在任何始终包含的源文件的开头意外输入“c”(如果不是artisan本身:

c<?php

现在,您可以使用原始未修改的文件替换Laravel源,也可以搜索上面的字符串,例如:

rgrep  "c<?php" .

在相关说明中:使用像Git这样的版本控制系统,您将不会遇到这些问题。

答案 2 :(得分:0)

我建议打开<?php class SmashingMagazine_BrandDirectory_Adminhtml_BrandController extends Mage_Adminhtml_Controller_Action { /** * Instantiate our grid container block and add to the page content. * When accessing this admin index page we will see a grid of all * brands currently available in our Magento instance, along with * a button to add a new one if we wish. */ public function indexAction() { // instantiate the grid container $brandBlock = $this->getLayout() ->createBlock('smashingmagazine_branddirectory_adminhtml/brand'); // add the grid container as the only item on this page $this->loadLayout() ->_addContent($brandBlock) ->renderLayout(); } /** * This action handles both viewing and editing of existing brands. */ public function editAction() { /** * retrieving existing brand data if an ID was specified, * if not we will have an empty Brand entity ready to be populated. */ $brand = Mage::getModel('smashingmagazine_branddirectory/brand'); if ($brandId = $this->getRequest()->getParam('id', false)) { $brand->load($brandId); if ($brand->getId() < 1) { $this->_getSession()->addError( $this->__('This brand no longer exists.') ); return $this->_redirect( 'smashingmagazine_branddirectory_admin/brand/index' ); } } // process $_POST data if the form was submitted if ($postData = $this->getRequest()->getPost('brandData')) { try { // image upload if(isset($_FILES['image']['name']) and (file_exists($_FILES['image']['tmp_name']))) { try { $path = Mage::getBaseDir('media') . DS . 'banner' . DS; $uploader = new Varien_File_Uploader('image'); $uploader ->setAllowedExtensions(array('jpg','png','gif','jpeg')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $destFile = $path.$_FILES[$image]['name']; $filename = $uploader->getNewFileName($destFile); $uploader->save($path, $filename); $data['img'] = $_FILES['image']['name']; } catch(Exception $e) { } } else { if(isset($data['image']['delete']) && $postData['image']['delete'] == 1) $data['image'] = ''; else unset($data['image']); } // continue $brand->addData($postData); $brand->save(); $this->_getSession()->addSuccess( $this->__($_FILES['image']['name']) ); // redirect to remove $_POST data from the request return $this->_redirect( 'smashingmagazine_branddirectory_admin/brand/edit', array('id' => $brand->getId()) ); } catch (Exception $e) { Mage::logException($e); $this->_getSession()->addError($e->getMessage()); } /** * if we get to here then something went wrong. Continue to * render the page as before, the difference being this time * the submitted $_POST data is available. */ } // make the current brand object available to blocks Mage::register('current_brand', $brand); // instantiate the form container $brandEditBlock = $this->getLayout()->createBlock( 'smashingmagazine_branddirectory_adminhtml/brand_edit' ); // add the form container as the only item on this page $this->loadLayout() ->_addContent($brandEditBlock) ->renderLayout(); } public function deleteAction() { $brand = Mage::getModel('smashingmagazine_branddirectory/brand'); if ($brandId = $this->getRequest()->getParam('id', false)) { $brand->load($brandId); } if ($brand->getId() < 1) { $this->_getSession()->addError( $this->__('This brand no longer exists.') ); return $this->_redirect( 'smashingmagazine_branddirectory_admin/brand/index' ); } try { $brand->delete(); $this->_getSession()->addSuccess( $this->__('The brand has been deleted.') ); } catch (Exception $e) { Mage::logException($e); $this->_getSession()->addError($e->getMessage()); } return $this->_redirect( 'smashingmagazine_branddirectory_admin/brand/index' ); } /** * Thanks to Ben for pointing out this method was missing. Without * this method the ACL rules configured in adminhtml.xml are ignored. */ protected function _isAllowed() { /** * we include this switch to demonstrate that you can add action * level restrictions in your ACL rules. The isAllowed() method will * use the ACL rule we have configured in our adminhtml.xml file: * - acl * - - resources * - - - admin * - - - - children * - - - - - smashingmagazine_branddirectory * - - - - - - children * - - - - - - - brand * * eg. you could add more rules inside brand for edit and delete. */ $actionName = $this->getRequest()->getActionName(); switch ($actionName) { case 'index': case 'edit': case 'delete': // intentionally no break default: $adminSession = Mage::getSingleton('admin/session'); $isAllowed = $adminSession ->isAllowed('smashingmagazine_branddirectory/brand'); break; } return $isAllowed; } } 并检查是否存在某种index.phpecho "c";。根据你的问题和评论,你的所有观点都有这样的字母似乎是索引文件或主要布局文件是问题所在。 (我倾向于print "c";文件,因为您在doctype之前看到了这封信。)