PDA

View Full Version : چگونه error handling کنیم



jionelmessi
شنبه 23 اسفند 1393, 13:27 عصر
با سلام
می خواستم بدونم وقتی دارم از متد save استفاده می کنم اگه مثلا رکوردی duplicate شد یا اروری داشتم چجور ahandle کنم به سمت view از طریق ajax

Muhammad-Ali
سه شنبه 26 اسفند 1393, 10:17 صبح
سلام
کجاش مشکل دارید؟
به عنوان نمونه به این کد نگاه کنید:


<? if($code == 500): ?>
<? Yii::log("\r\n---\r\n".$code.' => '.$message, 'error', 'site') ?>
<div class="flash-error">
مشکلی رخ داده، لطفا مجدداً امتحان کنید.
</div>
<? else: ?>
<div class="http-notice">
<h3>Error <?php echo $code; ?></h3>
<div class="error">
<?php echo CHtml::encode($message); ?>
</div>
</div>
<? endif ?>

این کد می تواند در ویوی views/site/error.php قرار بگیرد. البته این فقط یک مثال است و شاید از لحاظ منطق mvc مشکل داشته باشد.
علت اینکه از ارور شماره 500 برای گرفتن خطاهایی که منظور شما بود استفاده کردم این هستش:


5xx Server Error

The server failed to fulfill an apparently valid request.

Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and indicate whether it is a temporary or permanent condition. Likewise, user agents should display any included entity to the user. These response codes are applicable to any request method.


لیست کامل وضعیت های پروتکل http (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)

jionelmessi
چهارشنبه 05 فروردین 1394, 12:46 عصر
من می خوام ارورایی که سمت دیتابیس مده رو بگیرم بفرستم ویو راهی هست؟

همچنین ارور هایی که با اجگس مفرستم سمت کنترلرو بگیره بده بهم نمدونم چجور اینکتارو کنم