本文整理匯總了PHP中Controller::halt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Controller::halt方法的具體用法?PHP Controller::halt怎麽用?PHP Controller::halt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Controller
的用法示例。
在下文中一共展示了Controller::halt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* 構造方法
*
* @access public
* @return boolean
*/
public function __construct()
{
if (!function_exists('eaccelerator')) {
Controller::halt('The eAccelerator extension to be loaded.');
}
return true;
}
示例2: __construct
/**
* 構造方法
*
* 用於初始化運行環境,或對基本變量進行賦值
*
* @access public
*
* @param array $params 數據庫連接參數,如主機名,數據庫用戶名,密碼等
*
* @return boolean
*/
public function __construct($params = array())
{
if (!extension_loaded('mongo')) {
Controller::halt('The mongo extension to be loaded!');
}
//參數分析
if (!$params || !is_array($params)) {
//加載數據庫配置文件.
$params = Configure::get('mongo');
}
$params = is_array($params) ? $params + $this->_defaultConfig : $this->_defaultConfig;
if (!isset($params['dbname']) || !$params['dbname']) {
Controller::halt('The file of MongoDB config is error, dbname is not found!');
}
try {
//實例化mongo
$this->_mongo = new Mongo($params['dsn'], $params['option']);
//連接mongo數據庫
$this->_dbLink = $this->_mongo->selectDB($params['dbname']);
//用戶登錄
if (isset($params['username']) && isset($params['password'])) {
$this->_dbLink->authenticate($params['username'], $params['password']);
}
return true;
} catch (Exception $exception) {
//拋出異常信息
throw new DoitException('MongoDb connect error!<br/>' . $exception->getMessage(), $exception->getCode());
}
}
示例3: query
/**
* 執行SQL語句
*/
public function query($sql, $link = null)
{
$link = $link ? $link : $this->db_link;
$result = mysql_query($sql, $link);
//file_put_contents('sql.txt', $sql . PHP_EOL, FILE_APPEND);
//日誌操作,當調試模式開啟時,將所執行過的SQL寫入SQL跟蹤日誌文件,便於DBA進行MYSQL優化。若調試模式關閉,當SQL語句執行錯誤時寫入日誌文件
if (SYS_DEBUG === false) {
if ($result == false) {
//獲取當前運行的namespace、controller及action名稱
$action_id = App::get_action_id();
$namespace_id = App::get_namespace_id();
$controller_id = App::get_controller_id();
$namespace_code = $namespace_id ? '[' . $namespace_id . ']' : '';
if (SYS_LOG === true) {
Log::write($namespace_code . '[' . $controller_id . '][' . $action_id . '] SQL execute failed :' . $sql . ' Error Code:' . $this->errno() . 'Error Message:' . $this->error());
}
}
} else {
//獲取當前運行的namespace、controller及action名稱
$action_id = App::get_action_id();
$namespace_id = App::get_namespace_id();
$controller_id = App::get_controller_id();
$sql_log_file = APP_ROOT . 'logs' . DIRECTORY_SEPARATOR . 'SQL_' . date('Y_m_d', $_SERVER['REQUEST_TIME']) . '.log';
$namespace_code = $namespace_id ? '[' . $namespace_id . ']' : '';
if ($result == true) {
if (SYS_LOG === true) {
Log::write($namespace_code . '[' . $controller_id . '][' . $action_id . ']:' . $sql, 'Normal', $sql_log_file);
}
} else {
Controller::halt($namespace_code . '[' . $controller_id . '][' . $action_id . '] SQL execute failed :' . $sql . '<br/>Error Message:' . $this->error() . '<br/>Error Code:' . $this->errno() . '<br/>Error SQL:' . $sql);
}
}
return $result;
}
示例4: __construct
/**
* 構造方法
*
* @access public
* @return boolean
*/
public function __construct()
{
if (!extension_loaded('apc')) {
Controller::halt('The apc extension to be loaded.');
}
return true;
}
示例5: __call
/**
* 類方法自動調用引導
*
* 用於處理類外調用本類不存在的方法時的信息提示
*
* @access public
*
* @param string $method 類方法名稱
* @param array $args 參數值。注:本參數為數組
*
* @return mixed
*/
public function __call($method, $args)
{
//參數分析
$method = strtolower($method);
if (in_array($method, array('count', 'max', 'min', 'sum', 'avg'))) {
array_unshift($args, $method);
return call_user_func_array(array($this, '_selectByFunction'), $args);
}
return Controller::halt("The method: {$method}() is not found in DbCommand class!", 'Normal');
}
示例6: __construct
/**
* 構造函數
*
* @access public
*
* @param array $params 數據庫連接參數,如主機名,數據庫用戶名,密碼等
*
* @return boolean
*/
public function __construct($options = null)
{
if (!extension_loaded('redis')) {
Controller::halt('The redis extension to be loaded!');
}
//當參數為空時,程序則自動加載配置文件中數據庫連接參數
if (!$options || !is_array($options)) {
$options = Configure::get('redis');
if (!$options) {
$options = array();
}
}
$options += $this->_defaultServer;
//連接數據庫
$this->_dbLink = new Redis();
$this->_dbLink->connect($options['host'], $options['port']);
return true;
}
示例7: __construct
/**
* 構造方法
*
* @access public
*
* @param array $params 數據庫連接參數,如主機名,數據庫用戶名,密碼等
*
* @return boolean
*/
public function __construct($options = null)
{
//分析memcache擴展模塊的加載
if (!extension_loaded('memcache')) {
Controller::halt('The memcache extension to be loaded before use!');
}
//獲取Memcache服務器連接參數
if (!$options || !is_array($options)) {
$options = Configure::get('memcache');
}
if (is_array($options) && $options) {
$this->_defaultOptions = $options + $this->_defaultOptions;
}
if (!$this->_defaultOptions['servers']) {
$this->_defaultOptions['servers'][] = $this->_defaultServer;
}
$this->_dbLink = new Memcache();
foreach ($this->_defaultOptions['servers'] as $server) {
$server += array('host' => '127.0.0.1', 'port' => 11211, 'persistent' => true);
$this->_dbLink->addServer($server['host'], $server['port'], $this->_defaultOptions['persistent']);
}
return true;
}
示例8: __construct
/**
* 構造方法
*
* 用於初始化運行環境,或對基本變量進行賦值
*
* @access public
*
* @param array $params 數據庫連接參數,如主機名,數據庫用戶名,密碼等
*
* @return boolean
*/
public function __construct($params = array())
{
//參數分析
if (!$params['dsn']) {
Controller::halt('database config params error!', 'Normal');
}
$params += $this->_defaultConfig;
//數據庫連接
try {
$flags = array(PDO::ATTR_PERSISTENT => $params['persistency'], PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
//實例化數據庫連接
$this->_dbLink = new PDO($params['dsn'], $params['username'], $params['password'], $flags);
} catch (PDOException $exception) {
//當調試模式關閉時
if (DOIT_DEBUG === false) {
//記錄錯誤日誌
Log::write("Database server connect error! Error Code:{$exception->getCode()} Error Message:{$exception->getMessage()}", 'Warning');
//提示錯誤信息
Controller::showMsg('數據庫連接失敗!');
}
//拋出異常信息
throw new DoitException('Database connect error!<br/>' . $exception->getMessage(), $exception->getCode());
}
//設置數據編碼
$driverName = $this->_dbLink->getAttribute(PDO::ATTR_DRIVER_NAME);
switch ($driverName) {
case 'mysql':
case 'pgsql':
$this->_dbLink->exec("SET NAMES {$params['charset']}");
break;
case 'sqlsrv':
$this->_dbLink->setAttribute(PDO::SQLSRV_ATTR_ENCODING, $params['charset']);
break;
}
return true;
}
示例9: halt
/**
* trigger_error()的簡化函數
*
* 用於顯示錯誤信息. 若調試模式關閉時(即:SYS_DEBUG為false時),則將錯誤信息並寫入日誌
* @access public
* @param string $message 所要顯示的錯誤信息
* @param string $level 日誌類型. 默認為Error. 參數:Warning, Error, Notice
* @return void
*/
public function halt($message, $level = 'Error')
{
return Controller::halt($message, $level);
}
示例10: __call
/**
* 類方法自動調用引導
*
* 用於處理類外調用本類不存在的方法時的信息提示
*
* @access public
*
* @param string $method 類方法名稱
* @param array $args 所調用類方法的參數
*
* @return mixed
*/
public function __call($method, $args)
{
//分析 findByxx()的類方法調用
if (strpos($method, 'findBy') !== false) {
//分析所要查詢的數據表字段名
$fieldsName = substr($method, 6);
$fieldsName = ltrim(strtolower(preg_replace('#[A-Z]#', '_\\0', $fieldsName)), '_');
array_unshift($args, "{$fieldsName}=?");
return call_user_func_array(array($this, 'getOne'), $args);
}
//分析 findAllByxx()的類方法調用
if (strpos($method, 'findAllBy') !== false) {
//分析所要查詢的數據表字段名
$fieldsName = substr($method, 9);
$fieldsName = ltrim(strtolower(preg_replace('#[A-Z]#', '_\\0', $fieldsName)), '_');
array_unshift($args, "{$fieldsName}=?");
return call_user_func_array(array($this, 'getAll'), $args);
}
return Controller::halt("The method: {$method}() is not found in Model class!", 'Normal');
}
示例11: readZip
/**
* 讀取名字為$name的zip包的內容
*
* @access public
*
* @param string $name 所讀取的zip文件的路徑
*
* @return array
*/
public function readZip($name)
{
//參數分析
if (!$name) {
return false;
}
if (!is_file($name)) {
Controller::halt("The File: {$name} is not found!");
}
// File information
$size = filesize($name);
// Read file
$fh = fopen($name, "rb");
$filedata = fread($fh, $size);
fclose($fh);
// Break into sections
$filesecta = explode("PK", $filedata);
// ZIP Comment
$unpackeda = unpack('x16/v1length', $filesecta[1]);
$comment = substr($filesecta[1], 18, $unpackeda['length']);
$comment = str_replace(array("\r\n", "\r"), "\n", $comment);
// CR + LF and CR -> LF
// Cut entries from the central directory
$filesecta = explode("PK", $filedata);
$filesecta = explode("PK", $filesecta[0]);
array_shift($filesecta);
// Removes empty entry/signature
$files = array();
foreach ($filesecta as $filedata) {
// CRC:crc, FD:file date, FT: file time, CM: compression method, GPF: general purpose flag, VN: version needed, CS: compressed size, UCS: uncompressed size, FNL: filename length
$entrya = array();
$unpackeda = unpack("v1version/v1general_purpose/v1compress_method/v1file_time/v1file_date/V1crc/V1size_compressed/V1size_uncompressed/v1filename_length", $filedata);
// Check for value block after compressed data
if ($unpackeda['general_purpose'] & 0x8) {
$unpackeda2 = unpack("V1crc/V1size_compressed/V1size_uncompressed", substr($filedata, -12));
$unpackeda['crc'] = $unpackeda2['crc'];
$unpackeda['size_compressed'] = $unpackeda2['size_uncompressed'];
$unpackeda['size_uncompressed'] = $unpackeda2['size_uncompressed'];
unset($unpackeda2);
}
$entrya['name'] = substr($filedata, 26, $unpackeda['filename_length']);
if (substr($entrya['name'], -1) == "/") {
continue;
}
$entrya['dir'] = dirname($entrya['name']);
$entrya['dir'] = $entrya['dir'] == "." ? "" : $entrya['dir'];
$entrya['name'] = basename($entrya['name']);
$files[] = $entrya;
}
return $files;
}
示例12: _loadViewFile
/**
* 加載視圖文件
*
* 加載視圖文件並對視圖標簽進行編譯
*
* @access protected
*
* @param string $viewFile 視圖文件及路徑
*
* @return string
*/
protected function _loadViewFile($viewFile)
{
//分析視圖文件是否存在
if (!is_file($viewFile)) {
Controller::halt("The view file: {$viewFile} is not found!", 'Normal');
}
$viewContent = file_get_contents($viewFile);
//編譯視圖標簽
return $this->_handleViewFile($viewContent);
}
示例13: show
//.........這裏部分代碼省略.........
$image = imagecreatefromgif($this->_imageUrl);
$this->_type = 'gif';
break;
case 2:
$image = imagecreatefromjpeg($this->_imageUrl);
$this->_type = 'jpg';
break;
case 3:
$image = imagecreatefrompng($this->_imageUrl);
$this->_type = 'png';
break;
case 4:
$image = imagecreatefromwbmp($this->_imageUrl);
$this->_type = 'bmp';
break;
}
//背景
$srcX = $imageWidth > $this->_width ? mt_rand(0, $imageWidth - $this->_width) : 0;
$srcY = $imageHeight > $this->_height ? mt_rand(0, $imageHeight - $this->_height) : 0;
imagecopymerge($this->_image, $image, 0, 0, $srcX, $srcY, $this->_width, $this->_height, 100);
imagedestroy($image);
//邊框
$borderColor = imagecolorallocate($this->_image, 255, 255, 255);
imagerectangle($this->_image, 1, 1, $this->_width - 2, $this->_height - 2, $borderColor);
} else {
//定義圖片類型
$this->_type = 'png';
//背景
$bgColorArray = !$this->_bgColor ? array(255, 255, 255) : $this->_bgColor;
$back_color = imagecolorallocate($this->_image, $bgColorArray[0], $bgColorArray[1], $bgColorArray[2]);
imagefilledrectangle($this->_image, 0, 0, $this->_width - 1, $this->_height - 1, $back_color);
//邊框
$borderColor = imagecolorallocate($this->_image, 238, 238, 238);
imagerectangle($this->_image, 0, 0, $this->_width - 1, $this->_height - 1, $borderColor);
}
//獲取驗證碼內容.
$this->getPincodeContent();
//驗證碼中含有漢字
if (!preg_match('~[\\x{4e00}-\\x{9fa5}]+~u', $this->_textContent)) {
//計算驗證碼的位數
$codeStrlen = strlen($this->_textContent);
//每位驗證碼所占用的圖片寬度
$perWidth = ceil(($this->_width - 10) / $codeStrlen);
for ($i = 0; $i < $codeStrlen; $i++) {
//獲取單個字符
$textContent = $this->_textContent[$i];
$bbox = imagettfbbox($this->_fontSize, 0, $this->_fontName, $textContent);
$fontW = $bbox[2] - $bbox[0];
$fontH = abs($bbox[7] - $bbox[1]);
$fontX = ceil(($perWidth - $fontW) / 2) + $perWidth * $i + 5;
$min_y = $fontH + 5;
$max_y = $this->_height - 5;
$fontY = rand($min_y, $max_y);
$fontColor = !$this->_fontColor ? imagecolorallocate($this->_image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)) : imagecolorallocate($this->_image, $this->_fontColor[0], $this->_fontColor[1], $this->_fontColor[2]);
imagettftext($this->_image, $this->_fontSize, 0, $fontX, $fontY, $fontColor, $this->_fontName, $textContent);
}
} else {
//分析驗證碼的位置
$bbox = imagettfbbox($this->_fontSize, 0, $this->_fontName, $this->_textContent);
$fontW = $bbox[2] - $bbox[0];
$fontH = abs($bbox[7] - $bbox[1]);
$fontX = ceil(($this->_width - $fontW) / 2) + 5;
$min_y = $fontH + 5;
$max_y = $this->_height - 5;
$fontY = rand($min_y, $max_y);
$fontColor = !$this->_fontColor ? imagecolorallocate($this->_image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)) : imagecolorallocate($this->_image, $this->_fontColor[0], $this->_fontColor[1], $this->_fontColor[2]);
imagettftext($this->_image, $this->_fontSize, 0, $fontX, $fontY, $fontColor, $this->_fontName, $this->_textContent);
}
//幹擾線
for ($i = 0; $i < 5; $i++) {
$line_color = imagecolorallocate($this->_image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imageline($this->_image, mt_rand(2, $this->_width - 3), mt_rand(2, $this->_height - 3), mt_rand(2, $this->_width - 3), mt_rand(2, $this->_height - 3), $line_color);
}
//將顯示的驗證碼賦值給session.
Session::set($this->_sessionName, $this->_textContent);
//當有headers內容輸出時.
if (headers_sent()) {
Controller::halt('headers already sent');
}
//顯示圖片,根據背景圖片的格式顯示相應格式的圖片.
switch ($this->_type) {
case 'gif':
header('Content-type:image/gif');
imagegif($this->_image);
break;
case 'jpg':
header('Content-type:image/jpeg');
imagejpeg($this->_image);
break;
case 'png':
header('Content-type:image/png');
imagepng($this->_image);
break;
case 'bmp':
header('Content-type:image/wbmp');
imagewbmp($this->_image);
break;
}
imagedestroy($this->_image);
}
示例14: moveFile
/**
* 文件重命名或移動文件
*
* @access public
*
* @param string $sourceFile 源文件
* @param string $destFile 新文件名或路徑
*
* @return boolean
*/
public static function moveFile($sourceFile, $destFile)
{
//參數分析
if (!$sourceFile || !$destFile) {
return false;
}
//文件及目錄分析
if (!is_file($sourceFile)) {
Controller::halt('The file:' . $sourceFile . ' is not found!');
}
self::_parseDir(dirname($destFile), true);
return rename($sourceFile, $destFile);
}
示例15: getConfig
/**
* 獲取項目配置文件內容
*
* 根據DoitPHP項目的配置文件名稱,獲取該項目配置文件的內容,並將該內容進行返回
*
* @access public
*
* @param string $fileName 項目配置文件名。注:不含“.php”後綴。
*
* @return array
*/
public static function getConfig($fileName)
{
//參數分析.
if (!$fileName) {
return false;
}
if (!isset(self::$_config[$fileName])) {
$filePath = BASE_PATH . '/config/' . $fileName . '.php';
//判斷文件是否存在
if (!is_file($filePath)) {
Controller::halt('The configuration file: ' . $fileName . '.php is not exists!', 'Normal');
}
$config = array();
include_once $filePath;
self::$_config[$fileName] = $config;
}
return self::$_config[$fileName];
}