实现功能,操作项可以单独删除,批量项可以批量删除,批量显示,隐藏(改广告的数据库的status_is的值);
1.视图关键点:
复制代码 代码如下:
id?>
复制代码 代码如下:
2.控制器:
复制代码 代码如下:
/**
* 批量操作
*
*/
public function actionBatch ()
{
if (XUtils::method() == 'GET') { //单个删除是get方式
$command = trim($_GET['command']);
$ids = intval($_GET['id']);
} else
if (XUtils::method() == 'POST') {
$command = trim($_POST['command']);
$ids = $_POST['id'];
is_array($ids) && $ids = implode(',', $ids);
} else {
XUtils::message('errorBack', '只支持POST,GET数据');
}
empty($ids) && XUtils::message('error', '未选择记录');
switch ($command) {
case 'adDelete':
parent::_acl('ad_delete');
parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'删除广告,ID:'.$ids));
parent::_delete(new Ad(), $ids, array ('ad' ), array ('attach_file' ));
break;
case 'adVerify':
parent::_acl('ad_verify');
parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'广告状态变更为显示,ID:'.$ids));
parent::_verify(new Ad(), 'verify', $ids, array ('ad' ));
break;
case 'adUnVerify':
parent::_acl('ad_verify');
parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'广告状态变更为隐藏,ID:'.$ids));
parent::_verify(new Ad(), 'unVerify', $ids, array ('ad' ));
break;
default:
throw new CHttpException(404, '错误的操作类型:' . $command);
break;
}
}
父类的删除函数:
复制代码 代码如下:
protected function _delete ($model = null, $id = '', $redirect = 'index', $attach = null, $pkField = 'id')
{
if ($attach) { //如果有附件要删除广告的图片
$data = $model->findAll($pkField . ' IN(:id)', array (':id' => $id ));
foreach ((array) $data as $row) {
foreach ((array) $attach as $value) {
if (! empty($row[$value])) {
@unlink($row[$value]);
}
}
}
}
$result = $model->deleteAll(array ('condition' => 'id IN(' . $id . ')' ));
//刷新缓存
self::_refreshCache($model);
$this->redirect($redirect);
}
复制代码 代码如下:
protected function _verify ($model = null, $type = 'verify', $id = '', $redirect = 'index', $cdField = 'status_is', $pkField = 'id')
{
$criteria = new CDbCriteria();
$criteria->condition = $pkField . ' IN(' . $id . ')';
$showStatus = $type == 'verify' ? 'Y' : 'N';
$result = $model->updateAll(array ($cdField => $showStatus ), $criteria);
//刷新缓存
self::_refreshCache($model);
$this->redirect($redirect);
}

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor
